/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __SCENE_CAMERA_H__
#define __SCENE_CAMERA_H__

#include "PQEngine.h"
#include "CameraObject.h"

namespace PQBuilder
{
	/*Game builder scene view camera.
	*/
	class SceneCamera
	{
	public:
		enum RotateMode
		{
			ROTATE_OBJECT_PIVOT,
			ROTATE_CAMERA_PIVOT,
		};
		static const int CAMERA_SPEED=1;
		static const int PAN_SPEED=1;
		static const int ROTATE_SPEED=1;
		static const int SCALE_SPEED=1;
		static const float CAMERA_EPSILON;
	public:
		SceneCamera(PQEngine::SceneObject* sceneObject);
		

		inline void setRenderType(Ogre::PolygonMode mode)
		{
			_camera->setPolygonMode(mode);
		}

		inline void setBackground(Ogre::ColourValue color)
		{
			_camera->setBackgroundColour(color);
			
		}

		void rotate(int x0,int y0,int x1,int y1);
		/*Rotate camera around current selected object.
		If none selected,then just rotate scene normally.
		*/
		void rotateObject(int x0,int y0,int x1,int y1);
		void pan(int x0,int y0,int x1,int y1);
		void scale(int x0,int y0,int x1,int y1);

		void forward();
		void backward();
		void leftward();
		void rightward();
		void upward();
		void downward();

		/*Frame game object specified by pointer
		@param object The game object's pointer.
		*/
		void frameObject(PQEngine::GameObject* object);

		/*Frame game object specified by object id
		@param object The game object's id.
		*/
		void frameObject(int id);

		/*Frame current selected game object.
		*/
		void frameObject();

	public:
		/** Update camera over time
        * @param deltaT Time delta period between update
        */
        void update(float deltaT);
	private:
		PQEngine::SceneObject* _sceneObject;
		PQEngine::CameraObject* _camera;
		RotateMode _rotateMode;
		
		Ogre::Vector3 _position;//camera target position
		bool _needUpdate;
	};
}

#endif
